<%@page import="model.Apply"%>
<%@page import="model.Mycomment"%>
<%@page import="model.Target"%>
<%@ page import="java.util.List"%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Merchant Application Review</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>

<%
String name = (String) session.getAttribute("username");
List<Apply> applylist = (List<Apply>) request.getAttribute("applylist");
List<Mycomment> commentlist = (List<Mycomment>) request.getAttribute("commentlist");
List<Target> targetlist = (List<Target>) request.getAttribute("targetlist");

if(name==null){
    out.print("Please login first! redirecting to Login...");
    response.setHeader("Refresh","1;URL=login.jsp");
}
else{
	out.print("Hello, " + name);
}
%>

<center>
<h3>Merchant Application Review</h3><br>

<table  border="1" width="900">
<%
	if(applylist!=null){
%>
		<tr><td><b>ApplyId</b></td>
			<td><b>User</b></td>
			<td><b>Target</b></td>
			<td><b>Reason</b></td>
			<td><b>Status</b></td>
			<td><b>Action</b></td></tr>
<% 
		for (Apply app: applylist){
%>
			<tr><td> <%=app.getApplyid()%> </td>
				<td> <%=app.getMyuser().getUsername()%> </td> 
				<td><a href="TargetServlet?targetID=<%=app.getTargetBean().getTargetid()%> ">
					<%=app.getTargetBean().getTargetname()%>  </a></td>
				<td> <%=app.getReason()%> </td>
				<td> <%=app.getApplyStatus()%> </td>
				<td>									
					<input type="button" name="approve" id="approve_btn" value="Approve" onclick="javascript:location.href='ReviewApply?applyId=<%=app.getApplyid()%>&review=pass'"/>
					<input type="button" name="deny" id="deny_btn" value="Deny" onclick="javascript:location.href='ReviewApply?applyId=<%=app.getApplyid()%>&review=deny'"/>				
				</td></tr>
<%
		}
	}
%>
</table><br>

<h3>Inspect User Comment</h3><br>
<table  border="1" width="900">
<%
	if(commentlist!=null){
%>
		<tr><td><b>Date</b></td>
			<td><b>User</b></td>
			<td><b>Reply to</b></td>
			<td><b>Target</b></td>			
			<td><b>Comment</b></td>			
			<td><b>Action</b></td></tr>
<% 
		for (Mycomment cm: commentlist){
%>
			<tr><td><%=cm.getPostdate().toString()%></td>				
				<td><%=cm.getMyuser1().getUsername()%></td> 
				<td><%=cm.getMyuser2()!=null? cm.getMyuser2().getUsername() : ""%></td> 
				<td><a href="TargetServlet?targetID=<%=cm.getTargetBean().getTargetid()%>">
					<%=cm.getTargetBean().getTargetname()%>  </a></td>				
				<td><p style="width:500px;word-wrap: break-word;"><%=cm.getContent()%></p> </td>				
				<td><input type="button" name="delele_cm" id="delele_cm_btn" value="delete" onclick="javascript:location.href='ReviewApply?commentId=<%=cm.getCommentid()%>'"/></td></tr>
<%
		}
	}
%>
</table><br>

<h3>Inspect Merchant Profile</h3><br>
<table  border="1" width="900">
<%
	if(targetlist!=null){
%>
		<tr>
			<td><b>Target</b></td>
			<td><b>Merchant</b></td>
			<td><b>Info</b></td>
			<td><b>Action</b></td></tr>
<% 
		for (Target target: targetlist){
%>
			<tr>
				<td><a href="TargetServlet?targetID=<%=target.getTargetid()%> ">
					<%=target.getTargetname()%>  </a></td>
				<td> <%=target.getMyuser()!=null? target.getMyuser().getUsername() : ""%> </td> 				
				<td> <%=target.getMchtinfo()%> </td>													
				<td><input type="button" name="delele_target" id="delele_target_btn" value="delete" onclick="javascript:location.href='ReviewApply?targetId=<%=target.getTargetid()%>'"/></td></tr>			
				
<%
		}
	}
%>
</table><br>

<br>
<td> <input type="button" name="return" id="return" value="Go back" onclick="javascript:location.href='Home'"/> </td>
</center>


</body>
</html>
